/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.forms.renderers;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author cbegg
 */
public class CentredCellRenderer extends DefaultTableCellRenderer {

    private TableCellRenderer nestedRenderer;

    public CentredCellRenderer() {
        nestedRenderer = null;
    }

    public CentredCellRenderer(TableCellRenderer nestedRenderer) {
        this.nestedRenderer = nestedRenderer;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {

        if (nestedRenderer != null) {

            JLabel label = (JLabel)(nestedRenderer.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column));

            label.setHorizontalAlignment(SwingConstants.CENTER);

            return label;

        } else {

            JLabel label = (JLabel)(super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column));

            label.setHorizontalAlignment(SwingConstants.CENTER);

            return label;
        }
    }
}
